<!--
 * @Description:厂端车辆查询--索赔历史明细
 * @Autor: 刘诗文
 * @Date: 2021-01-26 16:02:36
 * @LastEditors: 马毅
 * @LastEditTime: 2021-03-29 13:28:34
-->
<template>
  <div>
    <FormPanel ref="formPanel" :list="formList" :cols="4" :labelWidth="130" :formType="type" :isSubmitBtn="false" />
    <BreakSpace label="维修项目列表" :containerStyle="{ marginBottom: '10px' }" />
    <FilterTable
      ref="maintenanceItems"
      height="auto"
      selectionType="single"
      :columns="maintenanceItemscolumns"
      :datakey="'rows'"
      :dataSource="maintenanceItemsList"
      :onSyncTableData="maintenanceItemsTableChange"
      columnsRef="maintenanceItemVehiclelsw"
      :onColumnsChange="columns => (this.maintenanceItemscolumns = columns)"
    >
    </FilterTable>
    <BreakSpace label="配件换上件列表" :containerStyle="{ marginBottom: '10px' }" />
    <FilterTable
      ref="replacementOfParts"
      height="auto"
      selectionType="single"
      :columns="replacementOfPartscolumns"
      :datakey="'rows'"
      :dataSource="replacementOfPartsList"
      :onSyncTableData="replacementOfPartsTableChange"
      columnsRef="replacementOfPartVehiclelsw"
      :onColumnsChange="columns => (this.replacementOfPartscolumns = columns)"
    >
    </FilterTable>
    <BreakSpace label="配件换下件列表" :containerStyle="{ marginBottom: '10px' }" />
    <FilterTable
      ref="replacementOfSpareParts"
      height="auto "
      selectionType="single"
      :columns="replacementOfSparePartscolumns"
      :datakey="'rows'"
      :dataSource="replacementOfSparePartsList"
      :onSyncTableData="replacementOfSparePartsTableChange"
      columnsRef="replacementOfSparePartVehiclelsw"
      :onColumnsChange="columns => (this.replacementOfSparePartscolumns = columns)"
    >
    </FilterTable>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { notifyAction, findTableItem, findFormItem } from '@/utils';
import { queryClaimHistoryDetail } from '@/api/customerRepair/customerInfo/ownerVehicleManagement';

export default {
  name: 'claimDeatilVehicle',
  mixins: [dictionary],
  props: ['formData', 'type'],
  data() {
    this.selectedData = null;
    this.BaseTable = null;
    return {
      formList: this.createFromList(),
      maintenanceItemscolumns: this.createTableColumnsMaintenanceItems(),
      replacementOfPartscolumns: this.createTableColumnsreplacementOfParts(),
      replacementOfSparePartscolumns: this.createTableColumnsreplacementOfSpareParts(),

      maintenanceItemsList: [], //维修项目列表
      replacementOfPartsList: [], //配件换上件列表
      replacementOfSparePartsList: [] //配件换上件列表
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table;
    console.log('索赔历史明细初始化');
    console.log(this.formData);

    // 初始化
    this.initialHandle();
  },
  methods: {
    createFromList() {
      return [
        {
          type: 'INPUT',
          label: '索赔单号：',
          fieldName: 'claimNo',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '维修经销商代码',
          fieldName: 'ownerCode',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '维修经销商名称',
          fieldName: 'ownerName',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '工单号：',
          fieldName: 'roNo',
          initialValue: '',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '索赔类型',
          fieldName: 'cmsClaimType',
          initialValue: '',
          itemList: [],
          disabled: true
        },
        {
          type: 'INPUT',
          label: '预授权单号：',
          fieldName: 'authNo',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '批量活动编号：',
          fieldName: 'batchCode',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '批量活动名称：',
          fieldName: 'batchName',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '主损件：',
          fieldName: 'partCode',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '主损件名称：',
          fieldName: 'partName',
          disabled: true
        },
        { type: 'INPUT', label: '供应商：', fieldName: 'supName', disabled: true },
        {
          type: 'SELECT',
          label: '车辆属性：',
          fieldName: 'ifCommStr',
          placeholder: '请选择',
          initialValue: '',
          itemList: [],
          disabled: true
        },
        {
          type: 'INPUT',
          label: '故障现象代码：',
          fieldName: 'faultCode',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '故障现象描述：',
          fieldName: 'faultName',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '一级代码：',
          fieldName: 'sysCode1',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '一级名称：',
          fieldName: 'sysName1',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '二级代码：',
          fieldName: 'sysCode2',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '二级名称：',
          fieldName: 'sysName2',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '三级代码：',
          fieldName: 'sysCode3',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '三级名称：',
          fieldName: 'sysName3',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '故障代码：',
          fieldName: 'sysCode4',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '故障描述：',
          fieldName: 'sysName4',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '分类：',
          fieldName: 'frCode',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '故障原因描述：',
          fieldName: 'frName',
          initialValue: undefined,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '质量报告单号：',
          fieldName: 'reportNo',
          initialValue: undefined,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '救援单号：',
          fieldName: 'outNo',
          initialValue: undefined,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '自费工单号：',
          fieldName: 'selfNo',
          disabled: true
        },
        {
          type: 'DATE',
          label: '自费配件销售日期',
          fieldName: 'selfSdate',
          initialValue: undefined,
          valueFormat: 'yyyy-MM-DD HH:mm:ss',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '自费配件销售里程',
          fieldName: 'selfMile',
          initialValue: undefined,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '自费配件使用时长',
          fieldName: 'selfUseHours',
          initialValue: undefined,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '自费配件使用里程',
          fieldName: 'selfUseMile',
          initialValue: undefined,
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '故障现象',
          fieldName: 'faultAppear',
          placeholder: '故障现象',
          rows: 3,
          selfCols: 4, // 元素占据几行
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '故障原因',
          fieldName: 'faultReason',
          placeholder: '故障原因',
          rows: 3,
          selfCols: 4, // 元素占据几行
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '维修方案',
          fieldName: 'cmsClaimPgm',
          placeholder: '维修方案',
          rows: 3,
          selfCols: 4, // 元素占据几行
          disabled: true
        },
        {
          type: 'UPLOAD_IMG',
          label: 'VIN',
          fieldName: 'wayPicture',
          placeholder: '上传身份证...',
          selfCols: 1,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            fixedSize: [5, 3],
            limit: 1,
            isCalcHeight: true
          },
          disabled: true
        },
        {
          type: 'UPLOAD_IMG',
          label: '里程（仪表）',
          fieldName: 'wayPicture1',
          placeholder: '上传身份证...',
          selfCols: 1,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            fixedSize: [5, 3],
            limit: 1,
            isCalcHeight: true
          },
          disabled: true
        },
        {
          type: 'UPLOAD_IMG',
          label: '车牌（车头）',
          fieldName: 'wayPicture2',
          placeholder: '上传身份证...',
          offsetRightCols: 1,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            fixedSize: [5, 3],
            limit: 1,
            isCalcHeight: true
          },
          disabled: true
        },
        {
          type: 'UPLOAD_IMG',
          label: '行驶证',
          fieldName: 'wayPicture3',
          placeholder: '上传身份证...',
          selfCols: 1,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            fixedSize: [5, 3],
            limit: 1,
            isCalcHeight: true
          },
          disabled: true
        },
        {
          type: 'UPLOAD_IMG',
          label: '故障照片',
          fieldName: 'wayPicture4',
          placeholder: '上传身份证...',
          initialValue: [],
          selfCols: 1,
          upload: {
            actionUrl: '/api/file/oss/upload',
            fixedSize: [5, 3],
            limit: 1,
            isCalcHeight: true
          },
          disabled: true
        },
        {
          type: 'UPLOAD_IMG',
          label: '其他文件',
          fieldName: 'wayPicture5',
          placeholder: '上传身份证...',
          selfCols: 1,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            fixedSize: [5, 3],
            limit: 1,
            isCalcHeight: true
          },
          disabled: true
        }
      ];
    },
    createTableColumnsMaintenanceItems() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '维修项目代码',
          dataIndex: 'labourCode'
        },
        {
          title: '维修项目名称',
          dataIndex: 'labourName'
        },
        {
          title: '索赔类型',
          dataIndex: 'cmsClaimType'
        },
        {
          title: '标准工时',
          dataIndex: 'labourHours'
        },
        {
          title: '索赔工时单价',
          dataIndex: 'cmsClaimPrice'
        },
        {
          title: '申请金额',
          dataIndex: 'cmsClaimAmount'
        },
        {
          title: '审核金额',
          dataIndex: 'checkAmount'
        }
      ];
    },
    createTableColumnsreplacementOfParts() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '配件代码', dataIndex: 'partCode' },
        { title: '配件名称', dataIndex: 'partName' },
        { title: '单位', dataIndex: 'partUnit' },
        { title: '数量', dataIndex: 'partCount' },
        { title: '索赔单价', dataIndex: 'cmsClaimPrice' },
        { title: '索赔总价', dataIndex: 'cmsClaimAmount' },
        { title: '是否电池', dataIndex: 'fEvStr' },
        { title: '电池编号', dataIndex: 'evNo' }
      ];
    },
    createTableColumnsreplacementOfSpareParts() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '配件代码', dataIndex: 'partCode' },
        { title: '配件名称', dataIndex: 'partName' },
        { title: '单位', dataIndex: 'partUnit' },
        { title: '数量', dataIndex: 'partCount' },
        { title: '配件回运类型', dataIndex: 'returnTypStr' },
        { title: '是否电池', dataIndex: 'fEvStr' },
        { title: '电池编号', dataIndex: 'evNo' }
      ];
    },

    // 维修列表回调函数
    maintenanceItemsTableChange(val) {
      this.maintenanceItemsList = val;
    },
    // 配件换上件回调函数
    replacementOfPartsTableChange(val) {
      this.replacementOfPartsList = val;
    },
    // 配件换下件回调函数
    replacementOfSparePartsTableChange(val) {
      this.replacementOfSparePartsList = val;
    },

    // 初始化
    async initialHandle() {
      const res = await queryClaimHistoryDetail({ ownerCode: this.formData.ownerCode, claimNo: this.formData.claimNo });
      if (res.resultCode === 200) {
        if (res.errMsg) {
          return notifyAction(res.errMst, 'error');
        } else {
          console.log('索赔历史明细');
          console.log(res.data);
          //表单赋值
          this.formList.forEach(x => {
            x.initialValue = res.data[x.fieldName];
            if (x.fieldName == 'ifCommStr') {
              x.initialValue = this.formData.ifCommStr;
            }
            if (x.fieldName == 'wayPicture') {
              x.initialValue = [res.data.fileList.find(y => y.type == '55141001') ? res.data.fileList.find(y => y.type == '55141001').fileUrl : null];
              console.log(x.initialValue, 11111);
            }
            if (x.fieldName == 'wayPicture1') {
              x.initialValue = [res.data.fileList.find(y => y.type == '55141002') ? res.data.fileList.find(y => y.type == '55141002').fileUrl : null];
              console.log(x.initialValue, 11111);
            }
            if (x.fieldName == 'wayPicture2') {
              x.initialValue = [res.data.fileList.find(y => y.type == '55141003') ? res.data.fileList.find(y => y.type == '55141003').fileUrl : null];
              console.log(x.initialValue, 11111);
            }
            if (x.fieldName == 'wayPicture3') {
              x.initialValue = [res.data.fileList.find(y => y.type == '55141004') ? res.data.fileList.find(y => y.type == '55141004').fileUrl : null];
              console.log(x.initialValue, 11111);
            }
            if (x.fieldName == 'wayPicture4') {
              x.initialValue = [res.data.fileList.find(y => y.type == '55141005') ? res.data.fileList.find(y => y.type == '55141005').fileUrl : null];
              console.log(x.initialValue, 11111);
            }
            if (x.fieldName == 'wayPicture5') {
              x.initialValue = [res.data.fileList.find(y => y.type == '55141006') ? res.data.fileList.find(y => y.type == '55141006').fileUrl : null];
              console.log(x.initialValue, 11111);
            }
          });
          // 维修项目列表赋值
          this.maintenanceItemsList = res.data.labourList;
          //配件换上件列表赋值
          this.replacementOfPartsList = res.data.partRList;
          //配件换下件列表赋值
          this.replacementOfSparePartsList = res.data.partList;
        }
      }
    }
  }
};
</script>
<style lang="less" scoped></style>
